@extends(layout, title: ((null == message) ? "Post" : "Update"))
@args Message message

@section("moreCss") {
<style>
  .error {color: red;}
</style>
}

<form action="/form" method="post">

  <input type="hidden" name="message.id" value="@message?.getId()">

  <div class="field">
    <label for="subject">Subject:</label>
    <div>
      <input type="text" id="subject" name="message.subject" value="@message?.subject">
    </div>
    <span class="error">@_error("message.subject")</span>
  </div>

  <br/>

  <div class="field">
    <label for="body">Body:</label>
    <div>
      <textarea id="body" name="message.body">@message?.body</textarea>
    </div>
    <span class="error">@_error("message.body")</span>
  </div>

  <p class="buttons">
    <a href="/">Cancel</a> |
    <input type="submit" value="Save this message" id="saveMessage">
    @if(message) {
    | <input type="button" value="Delete this message" id="deleteMessage">
    }
  </p>

</form>

@if(message) {
<script>
  $('#deleteMessage').on('click', function() {
      $.delete("/message/@message.getId()", function() {
          alert("Message deleted");
          location.href = "/";
      })
  })
</script>
}